package modele.cases;

import modele.agent.interfaces.AgentInterface;
import modele.cases.interfaces.CaseAbstract;
import modele.cases.interfaces.CaseInterface;
import modele.cases.interfaces.CasesInterface;

public class CaseConway extends CaseAbstract {

	private int x, y;
	private CasesInterface casesAround;
	private AgentInterface agent;

	@Override
	public AgentInterface getAgent() {
		return agent;
	}

	public CaseConway(int coordX, int coordY, AgentInterface agent) {
		casesAround = new Cases();
		this.x = coordX;
		this.y = coordY;
		this.agent = agent;
		this.agent.setAgentCase(this);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getNbAliveAround() {
		int aliveAround = 0;
		for (CaseAbstract cas : casesAround.getCases()) {
			if (((CaseConway) cas).hasAliveAgent())
				aliveAround++;
		}
		return aliveAround;
	}

	public boolean hasAliveAgent() {

		return agent.isAlive();
	}

	@Override
	public void giveNeighbour(int i, CaseAbstract neighbour) {
		casesAround.put(i, neighbour);

	}

}
